//
//  TestKeepVC.swift
//  UIScrollView的快速使用
//
//  Created by hongfei tam on 2019/6/24.
//  Copyright © 2019 YQ05. All rights reserved.
//

import UIKit

class TestKeepVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        //原始图片
        let image = UIImage(named: "image.jpg")!
        
        //将图片转成 400 * 300 尺寸
        let image2 = image.scaled(to: CGSize(width: 400, height: 300))
        // Do any additional setup after loading the view.
        
//        方法一：将其转换成UIImage对象，再通过UIImageJPEGRepresentation或UIImagePNGRepresentation方法转成NSData
//        这种方法不推荐，因为这个其实对图片进行了压缩转换，不再是图片的原始数据（像如果是gif动态图会变成静态图片），同时照片原来附带的拍摄信息什么的也会丢失。
//        1
//        2
//        3
//        var representation =  myAsset.defaultRepresentation()
//        var image = UIImage(CGImage:representation.fullResolutionImage().takeUnretainedValue())
        var data:NSData = image2.jpegData(compressionQuality: 1.0) as! NSData//UIImageJPEGRepresentation(image2, 1.0)
        
        
        
//        原文出自：www.hangge.com  转载请保留原文链接：http://www.hangge.com/blog/cache/detail_759.html
        
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}


